/*
 * Copyright (c) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "nativeimageadapter_fuzzer.h"
#define CAMERA_MANAGER_ADAPTER_IMPL

#define private public
#include "iconsumer_surface.h"
#include "native_image_adapter_impl.h"

using namespace OHOS::NWeb;

namespace OHOS {

bool NativeImageAdapterFuzzTest(const uint8_t* data, size_t size)
{
    std::shared_ptr<NativeImageAdapterImpl> imagerAdapter = std::make_shared<NativeImageAdapterImpl>();
    imagerAdapter->UpdateSurfaceImage();
    imagerAdapter->AquireNativeWindowFromNativeImage();
    imagerAdapter->AttachContext(1);
    imagerAdapter->DetachContext();
    uint32_t textureId = 1;
    uint32_t textureTarget = 1;
    imagerAdapter->CreateNativeImage(textureId, textureTarget);
    imagerAdapter->UpdateSurfaceImage();
    imagerAdapter->AquireNativeWindowFromNativeImage();
    imagerAdapter->AttachContext(1);
    imagerAdapter->DetachContext();
    imagerAdapter->GetTimestamp();
    float matrix[16] = { 0 };
    imagerAdapter->GetTransformMatrix(matrix);
    uint64_t surfaceId = 1;
    imagerAdapter->GetSurfaceId(&surfaceId);
    imagerAdapter->SetOnFrameAvailableListener(nullptr);
    imagerAdapter->UnsetOnFrameAvailableListener();
    imagerAdapter->DestroyNativeImage();
    return true;
}
} // namespace OHOS

/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    /* Run your code on data */
    OHOS::NativeImageAdapterFuzzTest(data, size);
    return 0;
}
